package com.mall.shop.controller;

import com.mall.shop.Result.Result;
import com.mall.shop.entity.CompanyEntity;
import com.mall.shop.service.CompanyService;
import com.mall.shop.vo.CityCompanyVo;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@EnableAutoConfiguration
@RequestMapping("/company")
public class CompanyController {

    @Resource
    CompanyService companyService;

    protected static final Logger logger = LoggerFactory.getLogger(CompanyController.class);

    @GetMapping
    public CompanyEntity getCompanyOne(@RequestParam Integer id) {
        CompanyEntity data = companyService.getCompany(id);
        return data;
    }

    @GetMapping("list")
    public Result getCompanyList() {
        List<CompanyEntity> data = companyService.getCompanyList();
        logger.error("xxx",data);
        return Result.success(data);
    }

    @GetMapping("city_list")
    public List<CityCompanyVo> getCityCompanyList() {
        List<CityCompanyVo> data = companyService.getCityCompanyList();
        return data;
    }

    @PostMapping("add")
    public CompanyEntity insertCompany() {
        CompanyEntity company = new CompanyEntity();
        company.setCity_code(220403L);
        company.setCompany("成都蚂蚁金服科技有限公司");
        company.setContact_person("王先生");
        company.setMember(99);
        company.setPhone("17725678989");

        companyService.insertCompany(company);

        return company;
    }

    @PostMapping("test")
    public CompanyEntity addCom(@RequestBody CompanyEntity company) {
        return company;
    }
}
